<template>
    <div class="tenantSearchContainer">
        <span class="inputLabel">租户编码</span>
        <el-input v-model="tenantSearchData.tenantId" placeholder="租户编码" class="searchInfoInput"></el-input>

        <el-input
            v-model="tenantName"
            placeholder="租户名称"
            class="searchInfoInput"
        >
            <template #prepend>
                <el-select v-model="tenantNameType" style="width: 90px">
                    <el-option label="中文" value="1" />
                    <el-option label="英文" value="2" />
                </el-select>
            </template>
        </el-input>

        <el-button type="primary" icon="SearchOutlined" class="searchButtonClass" :loading="searchLoading" @click="queryUserInfo()">搜索</el-button>
        <el-button icon="RedoOutlined" @click="resetInput()">重置</el-button>
    </div>
</template>

<script>
import {tenantInfoQuery} from "@/request/tenant";

export default {
    name: "TenantSearch",
    data() {
        return {
            tenantName: "",
            tenantNameType: "1",
            searchLoading: false
        }
    },
    computed: {
        tenantSearchData() {
            return this.$store.state.tenantSearchData;
        }
    },
    methods: {
        queryUserInfo() {
            this.searchLoading = true
            if (this.tenantNameType === '1') {
                this.tenantSearchData.tenantNameCn = this.tenantName;
                this.tenantSearchData.tenantName = '';
            } else if (this.tenantNameType === '2') {
                this.tenantSearchData.tenantName = this.tenantName;
                this.tenantSearchData.tenantNameCn = '';
            }
            tenantInfoQuery(this.tenantSearchData).then(res => {
                if (res.code === '200') {
                    this.$store.state.tenantDataList = res.data
                }
                this.searchLoading = false
            }).catch(res => {
                this.searchLoading = false
            })
        },
        resetInput() {
            this.$store.state.tenantSearchData = {
                tenantId: '',
                tenantName: '',
                tenantNameCn: '',
                tenantNameType: ''
            }
            this.tenantName = ''
            this.tenantNameType = '1'
        }
    }
}
</script>

<style scoped lang="less">
.tenantSearchContainer {
    width: 100%;
    height: 10%;
    .searchInfoInput {
        width: 15%;
        padding-left: 1%;
    }
    .inputLabel {
        padding-left: 1%;
        font-weight: 700;
        font-size: 15px;
        color: #606266;
    }
    .searchButtonClass {
        margin-left: 1%;
    }
}
</style>